function[object_outline,outline]=counter(m)
% hObject    handle to edge (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
temp1=m;
[row,col]=size(m);
temp2=zeros(row,col);
L=bwlabel(temp1);
stat=regionprops(L,'Area');
n=length(stat);
outline=[];
label=1;
while (n)                                                                 %the first while
flag1=1;
for i=1:row;
    for j=1:col;
        if (temp1(i,j)==1)&(L(i,j)==label)&(flag1)
            startx=i;
            starty=j;
            flag1=0;
        end
    end
end
temp2(startx,starty)=255;
p_code=[0,-1;1,-1;1,0;1,1;0,1;-1,1;-1,0;-1,-1];
p_n=3;
crrentx=startx;
crrenty=starty;
outline=cat(2,outline,[crrentx,crrenty]');
flag2=1;
while  (flag2)&(stat(label).Area)                         %the second while
    p_n=p_n-2;
    if (p_n==0) 
        p_n=8;
    end
    if (p_n==-1)
        p_n=7;
    end
    flag3=1;
    count=8;
    while (count)&(flag3)                    %the third while
        x=crrentx+p_code(p_n,1);
        y=crrenty+p_code(p_n,2);
        if (L(x,y)==label)
            crrentx=x;
            crrenty=y;
            temp2(crrentx,crrenty)=255;
            outline=cat(2,outline,[crrentx,crrenty]');
            flag3=0;
        end        
        if (flag3)
           p_n=p_n+1;
             if (p_n==9)
             p_n=1;
             end
        end
        count=count-1;
    end                                       %the third while
         
    if (crrentx==startx)&(crrenty==starty)
        flag2=0;
    end
    stat(label).Area=stat(label).Area-1;
end                                                 %the second while
n=n-1;
label=label+1;
end                                                             %the first while                
object_outline=im2bw(temp2);






